<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { gamesApi } from "@/api/controller";
  import xmImage from '@/components/xmImage/index.vue';
  import shopForm from './shopForm.vue';
  const shopFormRef = ref()
  const action = reactive({
    list:[] as Array<any>
  }),
  showType = [
    { label:'显示', type:1 },
    { label:'隐藏', type:2 },
  ] as Array<any>,
  listQuery = reactive({
    if_show:''
  })
  const handleForm = (row:any = {})=>{
    shopFormRef.value.openDialog({
      ...row,
      showType
    })
  }
  const getConfigInfo = async()=>{
    const res = await gamesApi.angerbirdGetShopList(listQuery)
    action.list = res?.data || []
  }
  onMounted(()=>{
    getConfigInfo()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">显示状态：</div>
          <el-select v-model="listQuery.if_show" placeholder="请选择显示状态">
            <el-option
              v-for="item in showType"
              :label="item.label"
              :value="item.type"
            />
          </el-select>
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="getConfigInfo">查询</el-button>
          <el-button type="primary" @click="handleForm({})">新增</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column min-width="120" prop="gift_id" label="礼物ID" />
      <el-table-column min-width="120" prop="gift_name" label="礼物名称" />
      <el-table-column min-width="120" prop="gift_price" label="礼物价格" />
      <el-table-column width="140" prop="gift_image" label="礼物图片">
        <template #default="scoped">
          <xmImage :src="scoped.row.gift_image" :list="[scoped.row.gift_image]" />
        </template>
      </el-table-column>
      <el-table-column min-width="120" prop="energy_coin" label="能量币数量" />
      <el-table-column width="140" prop="if_show" label="是否显示">
        <template #default="scoped">
          <el-icon>
            <SuccessFilled v-if="scoped.row.if_show == 1" style="color: #67C23A;" />
            <CircleCloseFilled v-if="scoped.row.if_show == 0" style="clear: #F56C6C;" />
          </el-icon>
        </template>
      </el-table-column>
      <el-table-column width="180" fixed=right label="操作">
        <template #default="scope">
          <el-button type="primary" @click="handleForm(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <shopForm ref="shopFormRef" @update-list="getConfigInfo" />
  </div>
</template>

<style lang='scss' scoped>
  
</style>